package com.waterms.action.front;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.waterms.model.User;
import com.waterms.service.UserService;

public class UserAction extends ActionSupport{
	private UserService userService;
	//private User user;
	
	
	public String register()
	{
		User u = new User();
       	HttpServletRequest request = ServletActionContext.getRequest();
       	String userName = request.getParameter("userName");
       	String location = request.getParameter("location");
       	String password = request.getParameter("Password");
       	String oldpassword = request.getParameter("oldPassword");
       	u.setUsername(userName);
       	u.setPassword(password);
       	u.setLocation(location);
       	userService.addUser(u);

		return SUCCESS;
	}
	


	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	//public User getUser() {
		//return user;
	//}
	//public void setUser(User user) {
		//this.user = user;
	//}
	

	public String login(){
		User u = new User();
       	HttpServletRequest request = ServletActionContext.getRequest();
       	String userName = request.getParameter("username");
       	String location = request.getParameter("location");
       	String password = request.getParameter("Password");
      	u.setUsername(userName);
       	u.setPassword(password);
       	u.setLocation(location);
       	if (userService.checkUser(u)){
       		
		   return SUCCESS;
       	}else{
       		return ERROR;
       	}
	}

}
